package com.xjnt.tvos.tvlibs;

import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.xjnt.tvos.tvlibs.jsbridge.CallProcess;
import com.xjnt.tvos.tvlibs.jsbridge.IClientCallback;
import com.xjnt.tvos.tvlibs.jsbridge.data.DataBuilder;
import com.xjnt.tvos.tvlibs.jsbridge.annotation.Param;
import com.xjnt.tvos.tvlibs.jsbridge.annotation.ApiMethod;
import com.xjnt.tvos.tvlibs.jsbridge.data.ParamConsts;
import com.xjnt.tvos.utils.NetStateUtils;

/**
 * Created by caoyong on 18-1-8.
 */

public class NativeClass {
    private Context mContext;
    public NativeClass(Context context) {
        this.mContext = context;
    }

    @ApiMethod("test")
    public void test(@Param(type = Param.ParamType.CALLBACK, value = ParamConsts.KEY_CALLBACK_PROCESS) CallProcess process) {
        final DataBuilder response = DataBuilder.build();
        JSONObject data = new JSONObject();
        data.put("netConnected", NetStateUtils.isNetworkConnected(mContext));
        response.put("data", data);
        process.onCompleted(new IClientCallback() {
            @Override
            public DataBuilder setResponse() {
                response.setResponseStatus(1, "OK");
                return response;
            }
        });
    }
}
